package cn.laixueit.controller;

import cn.laixueit.pojo.Student;
import cn.laixueit.service.StudentService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class StudentController {

    @Autowired
    private StudentService studentService;

    @PostMapping("/findPage")
    public PageInfo<Student> findPage(@RequestParam(defaultValue = "1")Integer start,
                                      @RequestParam(defaultValue = "5")Integer size,
                                      @RequestBody Student student){
        PageInfo<Student> pageInfo = studentService.findPage(start, size, student);
        return pageInfo;
    }

    @PostMapping("/save")
    public Boolean save(@RequestBody Student student){
        studentService.save(student);
        return true;
    }

    @GetMapping("/findById/{id}")
    public Student findById(@PathVariable("id")Integer id){
        return studentService.findById(id);
    }

    @PostMapping("/update")
    public Boolean update(@RequestBody Student student){
        studentService.update(student);
        return true;
    }

}
